package spring.angularjs.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import spring.angularjs.domain.Reporttransaction;
import spring.angularjs.domain.Transaction;

@Repository
public class TransactionDAOImpl implements TransactionDAO {
	
	@Autowired
	private SessionFactory sessionfactory;

	@Override
	public List<Transaction> getListTransaction() {
		return sessionfactory.getCurrentSession().createCriteria(Transaction.class).list();
	}

	@Override
	public List<Transaction> getListTransactionNotReport() {
		Query query = sessionfactory.getCurrentSession().createQuery("select a from Transaction a where a.statusreport = :m");
		query.setParameter("m", "no");
		return query.list();
	}

	@Override
	public Transaction getTransacionById(String id) {
		return (Transaction) sessionfactory.getCurrentSession().get(Transaction.class, id);
	}

	@Override
	public void updateTransaction(Transaction tr) {
		sessionfactory.getCurrentSession().update(tr);
	}

}
